package com.xd.pre.modules.tpshop.controller;


import com.xd.pre.common.utils.Result;
import com.xd.pre.modules.tpshop.domain.TpUserLevel;
import com.xd.pre.modules.tpshop.service.ITpUserLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lx
 * @since 2020-06-03
 */
@RestController
@RequestMapping("/userLevel")
public class TpUserLevelController {

    @Autowired
    private ITpUserLevelService ul_biz;


    // http://localhost:8080/tpshop_server/userLevel/findUserlevel_byLevelId?levelId=3			// 测试已通过！！
    @RequestMapping(value = "/findUserlevel_byLevelId", method = RequestMethod.GET)
    public Result findUserlevel_byLevelId(HttpServletRequest request) { //(Short levelId)

        System.out.println("测试--1-request.getParameter(username)-->: " + request.getParameter("levelId")); //

        Result result = new Result();
        Map<Object, Object> map = null;

        String levelId = request.getParameter("levelId"); //
        if (null != levelId && !"".equals(levelId)) {
            TpUserLevel userlevel = ul_biz.getById(levelId);
//            TpUserLevel userlevel = ul_biz.findUserlevel_byLevelId(Short.parseShort(levelId));
            map = new HashMap<Object, Object>();
            map.put("level", levelId);//userlevel.getLevelId()也可以
            map.put("levelName", userlevel.getLevelName());
        }
//		else{
//			map.put("level", 	 "所查结果为null ！！！");//
//		}
        result.setData(map);

        return result;
    }


//    public PrintWriter getConn(){
//        HttpServletResponse response=ServletActionContext.getResponse();
//        response.setContentType("text/html; charset=utf-8");
//        try {
//            PrintWriter out=response.getWriter();
//            return out;
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
}
